package com.aggron.controller;


import com.aggron.common.JsonData;
import com.aggron.constants.ControllerConstants;
import com.aggron.params.DeptParams;
import com.aggron.service.ISysDeptService;
import com.aggron.service.SysTreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuhuan
 * @since 2018-06-02
 */
@RestController
@RequestMapping("/sys/dept")
public class SysDeptController {

    @Autowired
    private ISysDeptService iSysDeptService;

    @Autowired
    private SysTreeService sysTreeService;

    @PostMapping("/save")
    public JsonData saveDept(@RequestBody DeptParams deptParams){
        iSysDeptService.save(deptParams);
        return JsonData.success(ControllerConstants.ADD_SUCCESS_MESSAGE);
    }

    @PostMapping("/update")
    public JsonData updateDept(@RequestBody DeptParams deptParams){
        iSysDeptService.update(deptParams);
        return JsonData.success(ControllerConstants.UPDATE_SUCCESS_MESSAGE);
    }

    @GetMapping("/tree")
    public JsonData deptTree(){
        return JsonData.success(sysTreeService.deptTree());
    }

    @PostMapping("delete")
    public JsonData deleteDept(@RequestBody DeptParams deptParams){
        iSysDeptService.delete(deptParams.getId());
        return JsonData.success(ControllerConstants.DELETE_SUCCESS_MESSAGE);
    }
}

